package gamesys.games.particlesystem
{
	import gamesys.games.particlesystem.core.ParticleSystemGroup;
	import gamesys.games.particlesystem.effects.GravityEffect;
	import gamesys.games.particlesystem.core.ParticleSystem;
	import gamesys.games.particlesystem.effects.LifeEffect;
	import gamesys.games.particlesystem.effects.VelocityEffect;
	import gamesys.games.particlesystem.emitters.IEmitter;
	import gamesys.games.particlesystem.emitters.SimpleEmitter;
	import gamesys.games.particlesystem.graphics.BitmapCanvas;
	import gamesys.games.particlesystem.utils.Range;

	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * @author robertthurston
	 */
	[SWF (width="800", height="600", frameRate="30", backgroundColor="0x222222")]
	public class PerticleSystemGroupTest extends AbstractTest
	{
		private static const SYSTEM_1 : String = "SYSTEM_1";
		private static const SYSTEM_2 : String = "SYSTEM_2";
		//
		private var _canvas : BitmapCanvas;
		private var _emitter : IEmitter;
		private var _particleSystemGroup : ParticleSystemGroup;

		override protected function init() : void
		{
			_canvas = new BitmapCanvas(800, 600);

			_emitter = new SimpleEmitter(400, 300);
			
			_particleSystemGroup = new ParticleSystemGroup();
			
			_particleSystemGroup.addParticleSystem(SYSTEM_1,  new ParticleSystem(_canvas, _emitter, ["FairyDust1"]));
			_particleSystemGroup.addEffect(SYSTEM_1, new VelocityEffect(new Range(2, 3), new Range(200, 160)));
			_particleSystemGroup.addEffect(SYSTEM_1, new LifeEffect(new Range(10, 10), new Range(100, 100), new Range(100, 100)));
			_particleSystemGroup.addEffect(SYSTEM_1, new GravityEffect(new Range(.4, .4)));
			
			_particleSystemGroup.addParticleSystem(SYSTEM_2,  new ParticleSystem(_canvas, _emitter, ["FairyDust2"]));
			_particleSystemGroup.addEffect(SYSTEM_2, new VelocityEffect(new Range(2, 3), new Range(-20, 20)));
			_particleSystemGroup.addEffect(SYSTEM_2, new LifeEffect(new Range(10, 10), new Range(100, 100), new Range(100, 100)));
			_particleSystemGroup.addEffect(SYSTEM_2, new GravityEffect(new Range(-.4, -.4)));
			
			addChild(_canvas);
		}

		override protected function onClick(event : MouseEvent) : void
		{
			_particleSystemGroup.addGroupParticles(50);
		}

		override protected function onEnterFrame(event : Event) : void
		{
			updateDebugger(_particleSystemGroup.totalParticles);
			
			_canvas.clear();
			_particleSystemGroup.update();
		}
	}
}
